/*
 * @Author: ShiJunJie
 * @Date: 2021-02-01 16:26:05
 * @LastEditors: ShiJunJie
 * @LastEditTime: 2021-09-08 14:43:54
 * @Descripttion: 用户相关 APi 接口
 */

import request from './request.js'
import storage from 'good-storage'

import router from '/@/router/index.js'

const api = {
  user: '/user/v1/'
}

export const DICT = {
  get: (parameter) => request.get(`${api.user}dict`, { parameter }),
  add: (parameter) => request.post(`${api.user}dict`, { parameter }),
  put: (parameter) => request.put(`${api.user}dict`, { parameter }),
  delete: (id) => request.delete(`${api.user}dict/${id}`)
}

export const USER = {
  /**
   * 用户登录
   * @param {*} parameter
   * @returns
   */
  login: async (parameter) => {
    // const res = await request.post(
    //   `${api.user}login?account=${parameter.account}&password=${parameter.password}`
    // )
    const res = { code: 0, data: { name: 'admin' } }
    if (res.code === 0) {
      storage.set('USER_TOKEN', { ...res.data, companyId: '123456' })
      console.log(storage.get('USER_TOKEN'))
      USER.getRouter()
      return Promise.resolve(res)
    } else {
      return Promise.reject(res)
    }
  },
  getRouter: () => {
    const res = [
      // {
      //   path: '/admin',
      //   name: '管理界面',
      //   component: 'admin'
      // },
      {
        path: '/admin/content',
        name: '管理界面的内容',
        component: 'content'
      }
    ]

    storage.set('USER_ROUTERS', res)
  }
}
